/**
 * Created by Administrator on 2016/9/26.
 */
    $(function(){

        var li1=$("#header .ul2 .li1");
        var li1a=$("#header .ul2 .li1 a");
        var oDiv=$("#header .ul2 .li1 .own");
        var oDiva=$("#header .ul2 .li1 .own a");
        var li2=$("#header .ul2 .li2");
        var li2a=$("#header .ul2 .li2 a");
        var oDiv2=$("#header .ul2 .li2 .own");
        var oDiva2=$("#header .ul2 .li2 .own a");
        var li3=$("#header .ul2 .li3");
        var li3a=$("#header .ul2 .li3 a");
        var oDiv3=$("#header .ul2 .li3 .own");
        var oDiva3=$("#header .ul2 .li3 .own a");
        var li4=$("#header .ul2 .li4");
        var li4a=$("#header .ul2 .li4 a");
        var oDiv4=$("#header .ul2 .li4 .own");
        var oDiva4=$("#header .ul2 .li4 .own a");
        var menuli=$("#menu ul li");
        var menulia=$("#menu ul li a");
        var menuli8=$("#menu ul .navhover") ;
        var searchBtn=$("#search-button")
        li1.mouseenter(function(){
            li1a.css({borderLeft:"1px solid #ccc",borderRight:"1px solid #ccc"});
            oDiva.css({border:"none"});
            oDiv.stop(true).slideDown(600,function(){
                oDiv.animate({opacity:1},500);
            });
        });
        li1.mouseleave(function(){
            li1a.css({borderLeft:"1px solid #fff",borderRight:"1px solid #fff"});
            oDiv.stop(true).slideUp(50,function(){
            });
        });

        li2.mouseenter(function(){
            li2a.css({borderLeft:"1px solid #ccc",borderRight:"1px solid #ccc"});
            oDiva2.css({border:"none"});
            oDiv2.stop(true).slideDown(600,function(){
                oDiv2.animate({opacity:1},500);
            });
        });
        li2.mouseleave(function(){
            li2a.css({borderLeft:"1px solid #fff",borderRight:"1px solid #fff"});
            oDiv2.stop(true).slideUp(50,function(){
            });

        });
        li3.mouseenter(function(){
            li3a.css({borderLeft:"1px solid #ccc",borderRight:"1px solid #ccc"});
            oDiva3.css({border:"none"});
            oDiv3.stop(true).slideDown(600,function(){
                oDiv3.animate({opacity:1},500);
            });
        });
        li3.mouseleave(function(){
            li3a.css({borderLeft:"1px solid #fff",borderRight:"1px solid #fff"});
            oDiv3.stop(true).slideUp(50,function(){
            });
        });
        li4.mouseenter(function(){
            li4a.css({borderLeft:"1px solid #ccc",borderRight:"1px solid #ccc"});
            oDiva4.css({border:"none"});
            oDiv4.stop(true).slideDown(600,function(){
                oDiv4.animate({opacity:1},500);
            });
        });
        li4.mouseleave(function(){
            li4a.css({borderLeft:"1px solid #fff",borderRight:"1px solid #fff"});
            oDiv4.stop(true).slideUp(50,function(){
            });
        });

        searchBtn.mouseenter(function(){
            searchBtn.css({backgroundPosition:'-310px -39px'});

        });
        searchBtn.mouseleave(function(){
            searchBtn.css({backgroundPosition:'right 0'});

        });
        /*nav部分*/
        menuli.mouseenter(function(){
            iIndex=$(this).index();
            menulia.eq(iIndex).css({color:"#eb744f"});
            if(iIndex==0){
                menuli8.stop(true).animate({left:20},200,function(){
                    menuli8.animate({opacity:1})
                })
            }else{
                menuli8.stop(true).animate({left:iIndex*104},200,function(){
                    menuli8.animate({opacity:1})
                })
            }

        });
        menuli.mouseleave(function(){
            menulia.eq(iIndex).css({color:"#000"});
            menuli8.stop(true).animate({left:-50},200,function(){})
        });
        menuli8.mouseenter(function(){

            menuli8.stop(true);
        });

        $(".box1 ul li").mouseenter(function(){
           var dex=$(this).index();

            $(".hidden").eq(dex).stop(true).animate({bottom:"0px"},100)
        });
        $(".box1").mouseleave(function(){
            $(".hidden").stop(true).animate({bottom:"-40px"},100)
        });


        $(".lab-more").mouseenter(function(){
            $(".lab-more dd").css({display:"block"})
        });
        $(".lab-more").mouseleave(function(){
            $(".lab-more dd").css({display:"none"})
        });

        $(".otherBox .otherlab").click(function(){
           var Index=$(this).index();
           $(".gift .box").css({display:"none"}).eq(Index).css({display:"block"})
       });
















        //吸顶
        var ebox=$(".ebox");
        var sp_back=$(".sp-back");
        var li1_back=$("#back .li1");
        var li1_box=$("#back .li1 .li1box");
        var li1_del=$("#back .li1 .li1box");
        var li2_back=$("#back .li2");
        var li2_box=$("#back .li2 div");
        var li2_del=$("#back .li2 div span");
        var li3_back=$("#back .li3 ");
        var li3_box=$("#back .li3 div ");
        var li3_del=$("#back .li3 div .ui-dialog-close");
        var li4_back=$("#back .li4");
        var li5_back=$("#back .li5");
        li1_back.click(function(){
            li1_box.css({display:"block"})
        });
        li1_del.click(function(){
            //return false;写在前面没效果
            li1_box.css({display:"none"});
            return false;
        });
        li2_back.click(function(){
            li2_box.css({display:"block"})
        });
        li2_del.click(function(){
            li2_box.css({display:"none"});
            return false;

        });
        li3_back.click(function(){
            $("#screen_locker").css({display:"block"});
            li3_box.css({display:"block"})
        });
        li3_del.click(function(){
            $("#screen_locker").css({display:"none"});
            li3_box.css({display:"none"});
            return false;

        });
        li4_back.mouseenter(function(){
            ebox.css({display:"block"});
        });
        li4_back.mouseleave(function(){
            ebox.css({display:"none"});
        });
        li5_back.mouseenter(function(){
            li5_back.css({background:"none"});
            sp_back.css({opacity:"1",background:"#ccc"});
        });
        li5_back.mouseleave(function(){
            li5_back.css({background:"url(../images/commonb.png) -1px 2px no-repeat #eee"});
            sp_back.css({opacity:"0"});
        });

//点击回到顶部按钮，页面滚动距离为零
        li5_back.click(function(){
            /*document.body.scrollTop = 0;*/
            $("body,html").animate({scrollTop:0},2000);
        });

        $(window).scroll(function(){
            /*var scrolltop=$(document).scrollTop();*/
            var scrolltop=document.body.scrollTop||document.documentElement.scrollTop;
            /*判断回到顶部按钮出现和消失*/
            if(scrolltop<=1660){
                li5_back.css({display:"none"});
                $(".fixedbox").css({
                    position:"absolute",
                    top:'1586px'
                })
            }
            else{
                li5_back.css({display:"block"});
                $(".fixedbox").css({
                    position:"fixed",
                    top:'0'
                })
            }
});


        $(".jiaru").click(function () {
            //var index=index($(this))

            // 要存储的商品信息：商品ID、商品名称、商品价格、商品数量、商品图片地址
            var
                iGoodsId 	= $(this).attr('data-id'),
                sGoodsTitle = $(this).attr('data-title'),
                iGoodsPrice = $(this).attr('data-price'),
                sGoodsSrc 	= $(this).attr('data-src');
            console.log(sGoodsSrc)

            var
                sGoods = getCookie('ggoods'),
                bBtn = true;

            if(sGoods === undefined) {
                var aGoods = [];
            } else {
                var aGoods = JSON.parse(sGoods);
            }

            for(var i =0; i < aGoods.length; i++) {
                if(aGoods[i].goodsId == iGoodsId){
                    aGoods[i].goodsNum++;
                    console.log( aGoods[i].goodsNum)
                    bBtn = false;
                }
            }

            if(bBtn) {
                var oGoods = {
                    goodsId: 	iGoodsId,
                    goodsTitle: sGoodsTitle,
                    goodsPrice: iGoodsPrice,
                    goodsSrc: 	sGoodsSrc,
                    goodsNum: 	1,
                };
                aGoods.push(oGoods);
            }
            //var aGoods = []; // 存储所有商品信息的数组

            console.log(aGoods);
            // 写入cookie
            setCookie('ggoods', JSON.stringify(aGoods), 7, '/');
            console.log(sGoods)
        })




    });